package core;

import Panel.MyPanel;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Iterator;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.Border;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import learn.Exceptions;

public class main {

	static JFrame okno;
	static ArrayList<JButton> buttons = new ArrayList<JButton>();
	static Iterator<JButton> iButtons;
	static JButton b;
	static JPanel content;

	static Border border = BorderFactory.createLineBorder(Color.black);

	public static void main(String[] args) {

		okno = new JFrame("Nauka Javy");
		JPanel menu = new JPanel();
		content = new JPanel();

		okno.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		ActionListener actionListener = new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				System.out.println(e.getActionCommand());
				switch (e.getActionCommand()) {
				case "Kania":
					MyPanel.setKaniaPanel(content);			break;
				case "Pasqal":
					MyPanel.setPasqalPanel(content);		break;
				case "Layouty":
					MyPanel.setLayoutPanel(content);		break;
				case "Pliki":
					MyPanel.setFilesPanel(content);			break;
				case "Wyjątki":
					new Exceptions();						break;
				case "A kysz!":
					System.exit(0);							break;
				case "Słowniczek!":
					MyPanel.setLibraryPanel(content);		break;
				case "Labirynt":
					MyPanel.setLabiryntPanel(content);		break;
				}
				okno.pack();
			}
		};		

		buttons.add(new JButton("Kania"));
		buttons.add(new JButton("Pasqal"));
		buttons.add(new JButton("Layouty"));
		buttons.add(new JButton("Pliki"));
		buttons.add(new JButton("Wyjątki"));
		buttons.add(new JButton("Pusty JButton ;)"));
		buttons.add(new JButton("Słowniczek!"));
        buttons.add(new JButton("Labirynt"));
		buttons.add(new JButton("A kysz!"));

		iButtons = buttons.iterator();

// Hubert
		
		/*
		GridBagConstraints c = new GridBagConstraints();
		GridBagConstraints d = new GridBagConstraints();
		JPanel pane = new JPanel(new GridBagLayout());
		c.gridx = 0;
		while (iButtons.hasNext()) {
			b = (JButton) iButtons.next();
			b.addActionListener(actionListener);
			if (b.getActionCommand().equals("A kysz!")) {
				d.ipady = 50;
				d.ipadx = 600;
				d.weightx = 0;
				d.gridwidth = buttons.size()-1;
				d.gridx = 1;
				d.gridy = 1;
				pane.add(b, d);
			} else {
				c.gridx++;
				c.gridy = 0;
				c.weightx = 0.5;
				pane.add(b, c);
			}
		}*/

// Kania 	
		while (iButtons.hasNext()) {
			b = (JButton) iButtons.next();
			b.addActionListener(actionListener);
			menu.add(b);
		}
		
		menu.setLayout( new FlowLayout() );
		content.setLayout( new GridLayout() );
		content.setBorder(border);
		
		okno.add(menu, BorderLayout.NORTH);
		okno.add(content, BorderLayout.CENTER);
		
		okno.pack();
		okno.setVisible(true);		
	}
}
